package distributedbank.server.messages;

import distributedbank.gui.messages.BalanceResponse;
import distributedbank.server.BankBranch;

/**
 * This is a request to deposit a certain amount (possibly negative) of cents to
 * a given account.
 */
public class Deposit
        extends Transaction {
    public static final long serialVersionUID = 1;

    private final int amount; // amount is the number of cents to deposit

    public Deposit(int branchId, int accountId, int transactionId,
            int fromPort, int amount) {
        super(branchId, accountId, transactionId, fromPort);
        this.amount = amount;
    }

    @Override
    public Acknowledgment runRequestSilent(BankBranch bankBranch) {
        System.out.println("Depositing " + this.amount + " to account "
                + this.accountId + " at branch " + this.branchId);
        int balance = bankBranch.getAccount(this.accountId).deposit(
                this.amount, this.transactionId);
        BalanceResponse message = new BalanceResponse(this.transactionId,
                this.branchId, this.accountId, balance);
        return message;
    }
}
